<%--
  Created by IntelliJ IDEA.
  User: Stiofan
  Date: 2016/12/15
  Time: 18:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/common/tags.jsp" %>

<aos:html title="房产基础信息采集" base="http" lib="ext">
    <aos:body>
    </aos:body>
</aos:html>
<aos:onready>
    <aos:viewport layout="fit">
        <aos:panel layout="column" columnWidth="1" border="false" autoScroll="true">
            <aos:formpanel id="fcjcxxForm" layout="column" columnWidth="1" autoScroll="true">
                <aos:fieldset title="房产基础信息采集" collapsible="false">
                    <aos:combobox id="isYz" name="isYz" fieldLabel="是否有证" value="true" columnWidth="0.25"
                                  dicField="isYzDm" onselect="fn_isYz" star="true" allowBlank="false"/>
                    <aos:textfield id="fczh" name="fczh" fieldLabel="房产证号" columnWidth="0.25" onenterkey="queryFcjcxx"/>
                    <aos:textfield id="fcbh" name="fcbh" fieldLabel="房产编号" columnWidth="0.25" onenterkey="queryFcjcxx"/>
                    <aos:textfield id="fcmc" name="fcmc" fieldLabel="房产名称" columnWidth="0.25" star="true"
                                   allowBlank="false"/>
                    <aos:textfield id="jzmj" name="jzmj" fieldLabel="建筑面积(平米)" columnWidth="0.25"
                                   regex="/^[0-9]+([.]{1}[0-9]{1,2})?$/" regexText="必输输入数字并且保留至多两位小数"
                                   msgTarget="under" star="true" allowBlank="false"/>
                    <aos:combobox id="fcytDm" name="fcytDm" fieldLabel="房产用途" columnWidth="0.25" dicField="fcytDm"
                                  star="true" allowBlank="false"/>
                    <aos:combobox id="fcjgDm" name="fcjgDm" fieldLabel="房产结构" columnWidth="0.25" dicField="fcjgDm"
                                  star="true" allowBlank="false"/>
                    <aos:textfield id="fczyz" name="fczyz" fieldLabel="房产总原值(元)" columnWidth="0.25"
                                   regex="/^[0-9]+([.]{1}[0-9]{1,2})?$/" regexText="必输输入数字并且保留至多两位小数"
                                   msgTarget="under" star="true" allowBlank="false"/>
                    <aos:datefield id="fcqdrq" name="fcqdrq" fieldLabel="实际取得日期" columnWidth="0.25" star="true"
                                   allowBlank="false"/>
                    <aos:datefield id="fcyxqq" name="fcyxqq" fieldLabel="房产有效期起" columnWidth="0.25"/>
                    <aos:datefield id="fcyxqz" name="fcyxqz" fieldLabel="房产有效期止" columnWidth="0.25"/>
                    <aos:textfield id="tdbh" name="tdbh" fieldLabel="土地编号" columnWidth="0.25"
                                   onenterkey="queryTdjcxxByTdbh" onblur="queryTdjcxxByTdbh" star="true"
                                   allowBlank="false"/>
                </aos:fieldset>
                <aos:fieldset title="坐落地址" collapsible="false">
                    <aos:hiddenfield id="xzqhdsDm" name="xzqhdsDm" fieldLabel="所属地市" columnWidth="0.25"
                                     value="620500" star="true" allowBlank="false"/>
                    <aos:combobox id="xzqhxqDm" name="xzqhxqDm" fieldLabel="所属县区" columnWidth="0.25"
                                  url="fcjcxxcjService.queryXzqhszDmBySjxzqhszDm" onselect="queryJdxzDmByXzqhszDm"
                                  readOnly="true" star="true" allowBlank="false"/>
                    <aos:combobox id="jdxzDm" name="jdxzDm" fieldLabel="街道(乡镇)"
                                  url="fcjcxxcjService.queryJdxzDmByXzqhszDm"
                                  columnWidth="0.25" onselect="querySqjqDmByJdxzDm" readOnly="true" star="true"
                                  allowBlank="false"/>
                    <aos:combobox id="zldzSqjqDm" name="zldzSqjqDm" fieldLabel="所属街(路、村)" columnWidth="0.25"
                                  url="tdjcxxcjService.querySqjqDmByJdxzDm" onselect="queryDlxdDmBySqjqDm"
                                  readOnly="true" star="true" allowBlank="false"/>
                    <aos:combobox id="zldzDlxdDm" name="zldzDlxdDm" fieldLabel="所属巷道" columnWidth="0.25"
                                  url="tdjcxxcjService.queryDlxdDmBySqjqDm"/>
                    <aos:textfield id="zldzLh" name="zldzLh" fieldLabel="所属路号" columnWidth="0.25"/>
                </aos:fieldset>
            <aos:fieldset title="同土地信息下已登记的房产信息" collapsible="false" layout="column" columnWidth="1">
                <aos:gridpanel id="fcjcxxGrid" layout="fit" forceFit="true" columnWidth="1" autoScroll="true"
                               url="fcjcxxcjService.queryAllFcjcxxByTdbh"
                               hidePagebar="true" features="summary">
                    <aos:selmodel type="checkbox" mode="single"/>
                    <aos:column dataIndex="fczh" header="房产证号" align="center"
                                summaryRenderer="function(){return '合计'}"/>
                    <aos:column dataIndex="fcbh" header="房产编号" align="center"/>
                    <aos:column dataIndex="fcmc" header="房产名称" align="center"/>
                    <aos:column dataIndex="jzmj" header="建筑面积" type="number" format="0.00" summaryType="sum"/>
                    <aos:column dataIndex="fczyz" header="房产总原值" type="number" format="0.00" summaryType="sum"/>
                    <aos:column dataIndex="fcyxqq" header="有效期起" type="date" format="Y-m-d"/>
                    <aos:column dataIndex="fcyxqz" header="有效期止" type="date" format="Y-m-d"/>
                </aos:gridpanel>
            </aos:fieldset>
            </aos:formpanel>

            <aos:window id="zfFcjcxxWin" title="作废房产基础信息" width="1000" maxHeight="460">
                <aos:formpanel id="zfFcjcxxForm" layout="column" autoScroll="true">
                    <aos:textareafield id="zfyy" name="zfyy" fieldLabel="作废原因" labelWidth="60" columnWidth="1"
                                       height="200"/>
                    <aos:docked dock="bottom" ui="footer">
                        <aos:dockeditem xtype="tbfill"/>
                        <aos:dockeditem text="作废" onclick="zfFcjcxxByFcbh" icon="del.png"/>
                        <aos:dockeditem text="关闭" onclick="#zfFcjcxxWin.close();" icon="close.png"/>
                    </aos:docked>
                </aos:formpanel>
            </aos:window>
            <aos:docked dock="bottom" ui="footer" columnWidth="1" layout="column" border="false">
                <aos:panel layout="column" columnWidth="1" border="false">
                    <aos:panel layout="column" columnWidth="0.5" center="true" animate="false" border="false">
                        <aos:button text="查询" columnWidth="0.2" margin="0 5" onclick="queryFcjcxx"/>
                        <aos:button id="btnSave" text="保存" columnWidth="0.2" margin="0 5" onclick="saveFcjcxx"/>
                        <aos:button id="btnZf" text="作废" columnWidth="0.2" margin="0 5"
                                    onclick="#zfFcjcxxWin.show();"/>
                        <aos:button id="btnNext" text="下一户" columnWidth="0.2" margin="0 5" onclick="clearForNext"/>
                        <aos:button text="重置" columnWidth="0.2" margin="0 5" onclick="resetFcjcxxForm"/>
                    </aos:panel>
                </aos:panel>
            </aos:docked>
        </aos:panel>
    </aos:viewport>
    <script type="text/javascript">
        function queryFcjcxx() {
            if (fcbh.getValue() === "" && fczh.getValue() === "") {
                AOS.err("必须输入房产编号、房产证号其中一项进行查询");
            } else {
                if (fczh.getValue() !== "" && fcbh.getValue() === "") {
                } else if (fczh.getValue() === "" && fcbh.getValue() !== "") {
                } else {
                    AOS.err("仅能通过房产编号、房产证号进行查询");
                    return;
                }
                var params = {
                    fcbh: fcbh.getValue(),
                    fczh: fczh.getValue()
                };
                AOS.ajax({
                    params: params,
                    url: "fcjcxxcjService.queryFcjcxx",
                    ok: function (data) {
                        if (data.appcode === "noFcjcxx") {
                            AOS.tip("未查询到相关信息，可以进行房产基础信息采集!");
                            queryXzqhszDmBySjxzqhszDm();
                            Ext.getCmp("btnSave").setDisabled(false);
                            AOS.read(fcbh);
                            AOS.read(fczh);
                        } else {
                            if (data.appcode === "war") {
                                AOS.warn(data.appmsg);//提示无权操作
                                Ext.getCmp("btnSave").setDisabled(true);
                                AOS.edit(fcbh);
                                AOS.edit(fczh);
                            } else if (data.appcode === "err") {
                                AOS.err(data.appmsg);//提示需要调整管理员
                                Ext.getCmp("btnSave").setDisabled(true);
                                AOS.edit(fcbh);
                                AOS.edit(fczh);
                            } else {
                                Ext.getCmp("btnSave").setDisabled(false);
                                AOS.tip("查询到相关信息，可以进行房产基础信息修改!");
                                AOS.edit(fcbh);
                                AOS.edit(fczh);
                            }
                            if (data.tdbh !== "") {
                                Ext.getCmp("tdbh").setValue(data.tdbh);
                                queryTdjcxxByTdbh();
                                AOS.edit(tdbh);
                            }
                            queryXzqhszDmBySjxzqhszDm();
                            AOS.setValues(fcjcxxForm, data);
                            queryJdxzDmByXzqhszDm();
                            AOS.setValues(fcjcxxForm, data);
                            querySqjqDmByJdxzDm();
                            AOS.setValues(fcjcxxForm, data);
                            if (data.fcqdrq !== "" && data.fcqdrq !== undefined) {

                                AOS.setValue("fcqdrq", Ext.Date.parse(data.fcqdrq.substr(0, 10), 'Y-m-d', true));
                            }
                            if (data.fcyxqq !== "" && data.fcyxqq !== undefined) {
                                AOS.setValue("fcyxqq", Ext.Date.parse(data.fcyxqq.substr(0, 10), 'Y-m-d', true));
                            }
                            if (data.fcyxqz !== "" && data.fcyxqz !== undefined) {
                                AOS.setValue("fcyxqz", Ext.Date.parse(data.fcyxqz.substr(0, 10), 'Y-m-d', true));
                            }
                        }
                    }
                });
            }
        }
        function saveFcjcxx() {
            if (AOS.valid(fcjcxxForm)) {
                AOS.ajax({
                    forms: fcjcxxForm,
                    url: "fcjcxxcjService.saveFcjcxx",
                    ok: function (data) {
                        if (data.appcode === "suc") {
                            AOS.tip("土地基础信息保存成功！");
                            AOS.setValues(fcjcxxForm, data);
                            if (data.fcqdrq !== "" && data.fcqdrq !== undefined) {
                                AOS.setValue("fcqdrq", Ext.Date.parse(data.fcqdrq.substr(0, 10), 'Y-m-d', true));
                            }
                            if (data.fcyxqq !== "" && data.fcyxqq !== undefined) {
                                AOS.setValue("fcyxqq", Ext.Date.parse(data.fcyxqq.substr(0, 10), 'Y-m-d', true));
                            }
                            if (data.fcyxqz !== "" && data.fcyxqz !== undefined) {
                                AOS.setValue("fcyxqz", Ext.Date.parse(data.fcyxqz.substr(0, 10), 'Y-m-d', true));
                            }
                            queryTdjcxxByTdbh();
                            Ext.getCmp("btnSave").setDisabled(true);
                        } else {
                            AOS.err(data.appmsg);
                        }
                    }
                });
            } else {
                AOS.err("请检查相关信息是否输入完整！");
            }
        }
        function resetFcjcxxForm() {
            AOS.reset(fcjcxxForm);
            AOS.edit(fcbh);
            AOS.edit(tdbh);
            AOS.edit(fczh);
            fcjcxxGrid_store.removeAll();

        }
        function queryXzqhszDmBySjxzqhszDm() {
            var sjxzqhsz_dm = "620500";
            var params = {
                sjxzqhszDm: sjxzqhsz_dm
            };
            xzqhxqDm_store.getProxy().extraParams = params;
            xzqhxqDm_store.reload();

        }
        function queryJdxzDmByXzqhszDm() {
            var xzqhsz_dm = xzqhxqDm.getValue();
            var params = {
                xzqhszDm: xzqhsz_dm
            };
            jdxzDm_store.getProxy().extraParams = params;
            jdxzDm_store.reload();

        }
        function querySqjqDmByJdxzDm() {
            var jdxzDm = Ext.getCmp("jdxzDm").getValue();
            var params = {
                jdxzDm: jdxzDm
            };
            zldzSqjqDm_store.getProxy().extraParams = params;
            zldzSqjqDm_store.reload();
        }
        function queryDlxdDmBySqjqDm() {
            var sqjqDm = Ext.getCmp("zldzSqjqDm").getValue();
            var params = {
                sqjqDm: sqjqDm
            };
            zldzDlxdDm_store.getProxy().extraParams = params;
            zldzDlxdDm_store.reload();
        }
        function queryTdjcxxByTdbh() {
            var param = {
                tdbh: tdbh.getValue()
            };
            AOS.ajax({
                params: param,
                url: "tdjcxxcjService.queryTdjcxxByTdbh",
                ok: function (data) {
                    if (data.appcode === "suc") {
                        queryXzqhszDmBySjxzqhszDm();
                        AOS.setValue("xzqhxqDm", data.xzqhxqDm);
                        queryJdxzDmByXzqhszDm();
                        AOS.setValue("jdxzDm", data.jdxzDm);
                        querySqjqDmByJdxzDm();
                        AOS.setValue("zldzSqjqDm", data.zldzSqjqDm);
                        queryDlxdDmBySqjqDm();
                        Ext.getCmp("btnSave").setDisabled(false);
                        Ext.getCmp("btnZf").setDisabled(false);
                        AOS.read(tdbh);
                        fcjcxxGrid_store.getProxy().extraParams = param;
                        fcjcxxGrid_store.reload();
                    } else if (data.appcode === "err") {
                        AOS.edit(tdbh);
                        AOS.err("未根据土地编号查询到相关土地信息，请先进行土地基础信息采集!");
                        AOS.setValue("xzqhxqDm", "");
                        AOS.setValue("jdxzDm", "");
                        AOS.setValue("zldzSqjqDm", "");
                        Ext.getCmp("btnSave").setDisabled(true);
                        Ext.getCmp("btnZf").setDisabled(true);
                    }
                }
            });
        }
        function fn_isYz() {
            var tmpIsYz = isYz.getValue();
            if (Ext.getCmp("tdbh").getValue() === "") {
                resetFcjcxxForm();
            }
            if (tmpIsYz === "true") {
                AOS.edit(fczh);
            } else {
                AOS.read(fczh);
                fczh.setValue("");
                queryXzqhszDmBySjxzqhszDm();
                Ext.getCmp("btnSave").setDisabled(false);
            }
            isYz.setValue(tmpIsYz);
        }
        function zfFcjcxxByFcbh() {
            var params = {
                fcbh: Ext.getCmp("fcbh").getValue()
            };
            AOS.ajax({
                params: params,
                forms: zfFcjcxxForm,
                url: "fcjcxxcjService.zfFcjcxxByFcbh",
                ok: function (data) {
                    if (data.appcode === "suc") {
                        AOS.tip("房产基础信息作废成功!");
                        btnSave.disabled = true;
                        queryTdjcxxByTdbh();
                    } else if (data.appcode === "err") {
                        AOS.err(data.appmsg);
                    }
                    zfFcjcxxWin.close();
                }
            });
        }
        function clearForNext() {
            var tmp = Ext.getCmp("tdbh").getValue();
            resetFcjcxxForm();
            Ext.getCmp("tdbh").setValue(tmp);
            AOS.read(tdbh);
            queryTdjcxxByTdbh();
        }
    </script>
    Ext.getCmp("btnSave").setDisabled(true);
    Ext.getCmp("btnZf").setDisabled(true);
</aos:onready>